import Vue from 'vue'
import Router from 'vue-router'
import menus from './config/menu-config'
// import {getMenus} from "@/config/api";

Vue.use(Router)

const routes = [];

// getMenus().then(res => {
//     console.log("===> ：" + JSON.stringify(res.data.data));
// });


// 侧边栏二级菜单路由
let LayoutChildren = [];
menus.forEach((item) => {
    if (item.path != null) {
        LayoutChildren.push({
            path: item.path,
            name: item.index,
            meta: {title: item.title},
            props: true,
            component: () => import(`./views/${item.name}`)
        })
    } else if (item.subs != null) {
        longxh(item.subs);
    }
})

function longxh(subs) {
    subs.forEach((cell) => {
        if (cell.path != null) {
            LayoutChildren.push({
                path: cell.path,
                name: cell.index,
                meta: {title: cell.title},
                props: true,
                component: () => import(`./views/${cell.name}`)
            })
        } else if (cell.subs != null) {
            longxh(cell.subs);
        }
    })
}

routes.push({
    path: '/',
    component: resolve => require(['./views/Login.vue'], resolve)
})
routes.push({
    path: '/Home',
    props: true,
    component: resolve => require(['./views/Home.vue'], resolve),
    meta: {title: '自述文件'},
    children: LayoutChildren
})
routes.push({
    path: '/Dashboard',
    redirect: '/dashboard'
})

export default new Router({
    routes
})
